<?php
class product extends database{
	protected $_table = "tbl_products";
	protected $_category = "tbl_category";
	public function listcate(){
		$sql = "select * from $this->_category";
		$this->query($sql);
		return $this->fetchall();
	}
	public function listpro(){
		$sql = "select * from $this->_table
				inner join tbl_category on tbl_category.cate_id = tbl_products.cate_id
		";
		$this->query($sql);
		return $this->fetchall();
	}
	public function add($name,$hot,$price,$info,$cateid,$img=""){
		if($img != NULL){ // Có ảnh
			$sql = "insert into $this->_table(pro_name,pro_hot,pro_price,pro_info,pro_image,cate_id) values('$name','$hot','$price','$info','$img','$cateid')";
		}else{
			$sql = "insert into $this->_table(pro_name,pro_hot,pro_price,pro_info,cate_id) values('$name','$hot','$price','$info','$cateid')";
		}
		$this->query($sql);
	}
	public function update($name,$hot,$price,$info,$cateid,$id,$img=""){
		if($img != NULL){ // Có ảnh
			$sql = "update $this->_table set pro_name='$name',pro_hot='$hot',pro_price='$price',pro_info='$info',pro_image='$img',cate_id='$cateid' where pro_id = '$id'";
		}else{
			$sql = "update $this->_table set pro_name='$name',pro_hot='$hot',pro_price='$price',pro_info='$info',cate_id='$cateid' where pro_id = '$id'";
		}
		$this->query($sql);
	}
	public function getdata($id){
		$sql = "select * from $this->_table where pro_id = '$id'";
		$this->query($sql);
		return $this->fetch();
	}
}